package cn.tedu.boot21.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Controller
public class HelloController {
    //http://localhost:8080/hello
    //当客户端向此地址发送请求时下面的hello方法会执行
    @RequestMapping("/hello")
    public void hello(HttpServletRequest request,HttpServletResponse response) throws IOException {
//        获取客户端传来的参数
        String info=request.getParameter("info");
        System.out.println("接收到了请求！");
        //设置响应类型 告诉客户端响应的内容为什么类型
        response.setContentType("text/html;charset=utf-8");
//        得到输出对象 异常输出
        PrintWriter pw =response.getWriter();
//        输出数据
        pw.println("<h1>恭喜你测试成功</h1>"+info);
//        关闭资源
        pw.close();
    }
}
